import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class Test {

    public static void main(String[] args) {
        //arrayList遍历
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(10);
        arrayList.add(12);
        arrayList.add(34);
        arrayList.add(56);
        System.out.println(arrayList);

        System.out.println("=========");

        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i)+" ");
        }
        System.out.println();

        System.out.println("=========");
        for(Integer x:arrayList) {
            System.out.print(x+" ");
        }
        System.out.println();

        //使用迭代器
        Iterator<Integer> it =arrayList.iterator();
        while(it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();

        ListIterator<Integer> it2=arrayList.listIterator();
        while(it2.hasNext()) {
            System.out.print(it2.next()+" ");
        }
        System.out.println();

        //从指定位置开始打印
        ListIterator<Integer> it3=arrayList.listIterator(arrayList.size());
        while(it3.hasPrevious()) {
            System.out.print(it3.previous()+" ");
        }
        System.out.println();
    }

    public static void main3(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();

        arrayList.add(10);
        arrayList.add(12);
        arrayList.add(34);
        arrayList.add(56);
        System.out.println(arrayList);

        List<Integer> list=arrayList.subList(1,3);//截取下标1到3的元素，不包括3

        list.set(0,99);//将下标为0的元素改为99
        System.out.println(list);
        System.out.println(arrayList);
    }

    public static void main2(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        List<Integer> list=new ArrayList<>();

        arrayList.add(10);
        arrayList.add(12);
        System.out.println(arrayList);
        arrayList.remove(0);//删除0下标
        System.out.println(arrayList);
//        arrayList.remove(new Integer(10));
        arrayList.remove(Integer.valueOf(10));
    }
    public static void main1(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        List<Integer> list=new ArrayList<>();

        arrayList.add(10);
        System.out.println(arrayList);

    }
}
